﻿window.onload = function initProcessPage() {
	modifyCss();
};
function getQueryString(name) {
	var url = window.location.search;
	url = decodeURI(url);
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = url.substr(1).match(reg);
	if (r != null) {
		return unescape(r[2]);
	}
	return null;
};

$(function() {
	
	 var str=window.location.search;
	
	str = getQueryString("id");
	if(str != null){
		$("#clientTitle").html("修改被授时终端信息");
	$.ajax({
		url :"../../client/client",
		type:"POST",
		data :{id:str},
		dataType : "json",
		success : function(data) {
			  $('<input />', {
			        id: 'modify',
			        name: 'modify',
			        type: 'hidden',
			        value:'update',
			      }).appendTo($('#tyForm'));
			$("#tyForm").formEdit(data.client);
		}
	})
	}
	
});
function save() {// 新增或修改的保存方法
	var url;
	url="../../client/new"; 
	var flag =$("#modify").val();
	if(flag == "update"){
		url="../../client?method=modClient"; 
	
	}
	$.ajax({
		type : "POST",
		url : url,
		data : $('#tyForm').serialize(),
		dataType : "json",
		success : function(data) {
			if(data.tip!=null)
				alert(data.tip);
			else
				alert("操作成功");
				window.location.href = '../../modules/timeClient/timeClient.html';
			
		},// end success
	});

}
function modifyCss() {
	document.getElementById("rightTab").style.width = document.documentElement.clientWidth
			- 250 + "px";
};

function hasClass(obj, cls) {
	return obj.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)'));
};

function addClass(obj, cls) {
	if (!this.hasClass(obj, cls)) {
		obj.className += " " + cls;
	}
};

function removeClass(obj, cls) {
	if (hasClass(obj, cls)) {
		var reg = new RegExp('(\\s|^)' + cls + '(\\s|$)');
		obj.className = obj.className.replace(reg, ' ');
	}
};
